using System;
using System.Collections.Generic;
using System.Linq;
using Db4objects.Db4o.Linq;

namespace MVCMS.Util.Persistence
{
    public class ObjectRepository<T> : Repository<T> where T : class
    {
        private string _dbpath;
        


        #region Repository<T> Members

        public IEnumerable<T> GetAll()
        {
            return Db4oManager.Client.Cast<T>();
        }

        public IEnumerable<T> Get(int start, int count)
        {
            return Db4oManager.Client.Cast<T>().Skip(start).Take(count);
        }

        public IQueryable<T> Find(System.Linq.Expressions.Expression<Func<T, bool>> expression)
        {
            return Db4oManager.Client.Cast<T>().Where(expression).AsQueryable();
        }

        public void Save(T item)
        {
            Db4oManager.WithContainer(container =>
                                          {
                                              /// TODO: http://www.codeproject.com/KB/database/LINQ_for_db4o.aspx#demo
                                          }
                );
        }

        public void Remove(T item)
        {
            Db4oManager.WithContainer(container => { container.Delete(item); });
        }

        #endregion
    }
}